package com.gzy.rpsm_admin.controller;

import com.gzy.rpsm_admin.pojo.Building;
import com.gzy.rpsm_admin.pojo.PageResult;
import com.gzy.rpsm_admin.pojo.ResponsePojo;
import com.gzy.rpsm_admin.service.BuildingService;
import com.gzy.rpsm_admin.service.BuildingServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * RestController声明BuildingController是一个控制器类，
 * 控制器中的方法用于接收客户端的HTTP请求，并返回相应的数据。
 */
@RestController
@Api(tags = "楼栋相关接口")
public class BuildingController {
    @Autowired // 使用Spring自动注入，注入BuildingService接口的实现类
    private BuildingService buildingService;
    //相当于 private BuildingService buildingService = new BuildingServiceImpl();

    @ApiOperation(value = "查询楼栋分页信息",
            response = Building.class,
            responseContainer = "list",
            // response = ResponsePojo.class,
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页数", defaultValue = "1", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "页面行数", defaultValue = "10", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "number", value = "楼栋编号", dataType = "String", paramType = "query")
    })
    /**
     * 处理HTTP请求(GET http://<host>/page/building)，
     * 请求示例：http://localhost:8080/page/building?current=1&size=10&number=xfjy
     * 其中请求中的current和size参数会被解析后赋值给下面函数中的current和size参数。
     * 函数携带相应参数调用service层的pageOfBuilding()方法，并返回响应结果。
     */
    @GetMapping("/page/building")
    public ResponsePojo<PageResult<Building>> pageOfBuilding(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            String number) {
        PageResult<Building> result = buildingService.pageOfBuilding(current, size, number);
        return ResponsePojo.success(result);
    }
}
